/*
 * Copyright (c) 2024-2024 Huawei Technologies Co., Ltd. All rights reserved.
 *
 * UniProton is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 * Create: 2024-05-05
 * Description: sbi 接口
 */

#ifndef __SBI_H
#define __SBI_H


typedef struct sbi_ret_s {
    long error;
    long value;
} sbi_ret_t;

// sbi_ret_t 返回值中关于 error 错误类型的说明
#define RET_SBI_SUCCESS              0  //sbi call执行成功
#define RET_SBI_FAILED              -1  //sbi call失败
#define RET_SBI_NOT_SUPPORT         -2  //sbi call不支持 [当某个扩展模块EID 或者扩展EID中的功能号FID不支持时候会出现]
#define RET_SBI_INVALID_PARAM       -3  //sbi call无效的参数 (a6 a7)
#define RET_SBI_DENIED              -4  //sbi call拒绝执行对应的功能
#define RET_SBI_INVALID_ADDRESS     -5
#define RET_SBI_ALREADY_AVAILABLE   -6
#define RET_SBI_ALREADY_STARTED     -7
#define RET_SBI_ALREADY_STOPPED     -8
#define RET_SBI_NO_SHMEM            -9


// 定义所有扩展对应的值的宏名字 
#define EXTENSION_ID_BASE           0x10
#define EXTENSION_ID_HSM            0x48534D
#define EXTENSION_ID_DEBUG          0x4442434E
#define EXTENSION_ID_HANG           0x53555350 
#define EXTENSION_ID_TIME           0x54494D45 
#define EXTENSION_ID_IPI            0x735049 
  
  


// 遵从sbi2.0 调用规范的头函数
// 调用传递参数的规范:
// a6 - SBI调用的扩展ID
// a7 - SBI调用扩展中对应的功能ID
// 调用过程的准则:
// 除了对a0 和 a1 作为返回值发生改变外，不会对任何寄存器发生改变
// 调用返回值参数的规范:
// a0 - 返回错误类型 
// a1 - 返回错误值

/* 扩展 EID */
#define EID_BASE                          0x10         //基础扩展

#define EID_HSM                           0x48534D     //Hart State Management状态管理扩展

#define EID_DEBUG                         0x4442434E   //调试控制台扩展

#define EID_HANG                          0x53555350   //系统挂起扩展

#define EID_TIME                          0x54494D45   //时钟扩展

#define EID_IPI                           0x735049     //IPI扩展

/* 基本扩展 */
#define FID_BASE_GET_SBI_VERSION          0x0   //获得SBI版本

#define FID_BASE_GET_SBI_IMPL_ID          0x1   //获得SBI实现ID

#define FID_BASE_GET_SBI_IMPL_VER         0x2   //获得SBI实现版本

#define FID_BASE_PROBE_SBI_EXTEN          0x3   //查询某个EID扩展是否可用

#define FID_BASE_GET_MHART_ID             0x4   //获取machine vendor id 机器厂商

#define FID_BASE_GET_MARCHID              0x5   //获取机器体系结构标识符

#define FID_BASE_GET_MIMPID               0x6   //获取机器实现标识符


/* Hart状态管理扩展 */
#define FID_HSM_SBI_HART_START            0x0   //启动hart

#define FID_HSM_SBI_HART_STOP             0x1   //停止hart

#define FID_SBI_HART_GET_STATUS           0x2   //获取hart的状态

#define FID_SBI_HART_SUSPEND              0x3   //挂起hart

/* 控制台扩展 */
#define FID_DEBUG_CONSOLE_WRITE           0x0   //控制台写入

#define FID_DEBUG_CONSOLE_READ            0x1   //控制台读取

#define FID_DEBUG_CONSOLE_WRITE_BYTE      0x2   //写单个字节到控制台

/* 系统复位扩展 */
#define FID_HANG_SBI_SYSTEM_SUSPEND       0x0   //系统挂起

/* 时钟扩展 */
#define FID_TIME_SET_TIMER                0x0   //为下一个事件设置时间

/* IPI 扩展 */
#define FID_IPI_SEND_IPI                  0x0   //发送IPI

#endif